package xxy.com.yangproject.ui.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;

import java.util.LinkedHashMap;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import xxy.com.yangproject.R;
import xxy.com.yangproject.databinding.ActivityMain5Binding;
import xxy.com.yangproject.global.Constant;
import xxy.com.yangproject.model.MyViewModel;
import xxy.com.yangproject.network.NetWorkManager;
import xxy.com.yangproject.ui.view.AdDialog;

public class Main5Activity extends AppCompatActivity {


    private ActivityMain5Binding viewDataBinding;
    LinkedHashMap<Integer, String> linkedHashMap;

    {
        linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put(1, "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3344241222,2470179097&fm=26&gp=0.jpg");
        linkedHashMap.put(2, "https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1473836766,4030812874&fm=26&gp=0.jpg");
        linkedHashMap.put(3, "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2270291680,4103254225&fm=26&gp=0.jpg");
    }

    public static void launcher(Context context){
        Intent intent = new Intent(context, Main5Activity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_main5);
        WebSettings settings = viewDataBinding.webviewMain5.getSettings();
        settings.setSupportZoom(false);
        settings.setBuiltInZoomControls(false);
        settings.setUseWideViewPort(false);
        settings.setSupportMultipleWindows(true);
        settings.setLoadWithOverviewMode(false);
        AdDialog adDialog = new AdDialog(Main5Activity.this, R.style.TestDialog, linkedHashMap);
        viewDataBinding.btShowDialog.setOnClickListener(v -> adDialog.show());

        //给webview设置地址
//        viewDataBinding.setWebviewUrl("http://www.baidu.com");
//        viewDataBinding.webviewMain5.loadUrl(viewDataBinding.getWebviewUrl());
    }

    public void test(){
        CountDownLatch countDownLatch = new CountDownLatch(1);   //it's effect is when wait for  a thread  to count down to 0 , then the main thread can go on
        countDownLatch.countDown();
        RecyclerView recyclerView = new RecyclerView(this);
        recyclerView.setAdapter(new MyAdapter());
    }

    public class MyAdapter extends RecyclerView.Adapter{
        //game
        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return null;
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return 0;
        }

        class MyViewHolder extends RecyclerView.ViewHolder{

            public MyViewHolder(@NonNull View itemView) {
                super(itemView);
                View viewById = itemView.findViewById(R.id.iv_ad);
            }

        }
    }
}